﻿require 'duration'

class Time
  
  def year_month_day
    strftime('%Y年%m月%d日')
  end  
  
  def hour_minute
    strftime('%H点%M分')
  end
  
  def self.duration(seconds)
    if seconds == 0
      '0秒'
    else
      original = Duration.new(seconds).to_s
      original.gsub(/weeks?/, '周').gsub(/days?/, '天').gsub(/hours?/, '小时').gsub(/minutes?/, '分').gsub(/seconds?/, '秒').delete(', and')
    end    
  end
  
  def self.duration_between(begin_time, end_time)
    self.duration(end_time - begin_time)
  end
  
  def duration_to(sometime)
    if self == sometime
      "现在"
    else 
      if self < sometime
        Time::duration(sometime - self) + "后"
      else
        Time::duration(self - sometime) + "前"        
      end
    end
  end
end
